package com.apes.fn.supp.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.audit.Auditing;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.HashMap;
import java.util.Map;

@Auditing
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SantouChannel.CONST_TABLE_NAME)
public class SantouChannel extends Model {

    public static final String CONST_TABLE_NAME = "sp_santou_channel";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "三头六臂渠道")
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    @Comment("供应商")
    private PartyRole supplier;//供应商（商家）

    @Column(name = "channel_number")
    @Comment("渠道码")
    private String channelNumber;

    @Column(name = "channel_name")
    @Comment("渠道名称")
    private String channelName;


    @Transient
    private Map channel;//渠道

    public Map getChannel() {
        if (channel == null){
            channel = new HashMap();
        }
        channel.put("id", channelNumber);
        channel.put("name", channelName);
        return channel;
    }

}
